import React,{memo,useEffect,useState} from 'react';
import "../../assets/Layout/login.scss";
import { Button, Checkbox, Form, Input,Drawer } from 'antd';
import Zhuce from './zhuce'
import ZhaoHui from './zhaohui'
import { useLocation } from 'react-router-dom'
import { useNavigate } from 'react-router'

function  Login(){
  const [open, setOpen] = useState(false);
  const [text,setText] = useState("登录");
  const [teype,setTeype] = useState(0);
  const navigate = useNavigate();
  useEffect(()=>{
    window.electron.ipcRenderer.send("open-size",{width:400,height:650,resizable:false})
  },[])

  const onFinish = (v)=>{
    console.log(v)
  }

  const onFinishFailed = (v)=>{
    console.log(v)
  }
  const showDrawer = (name,teype) => {
    setOpen(true);
    setText(name)
    setTeype(teype)
  };

  const  onSuccess = async ()=>{
    localStorage.setItem("token","111")
    window.electron.ipcRenderer.send("open-size",{width:900,height:680,resizable:true})
     let data =   await window.electron.ipcRenderer.invoke('getUserInfo',{id:1})
    console.log(data,'查询的数据')
    navigate("/")
    console.log("登录了",window.location.href)
  }


  const onClose = () => {
    setOpen(false);
    setText('登录')
  };

  return <>
    <div className="login-main">
      <div className="login-top"></div>
      <div className="login-bt">
        {text}
      </div>
      <div className="login-main-box">
        <div className="login-title">欢迎回来</div>
        <div className="login-title-tis">继续登录您的账号!</div>
        <div className="login-from">
          <Form
            name="from"
            initialValues={{ remember: true }}
            layout={'horizontal'}
            onFinish={onFinish}
            onFinishFailed={onFinishFailed}
            autoComplete="off"
          >
            <Form.Item label="邮箱">
              <Input className="fromItem"  placeholder="登录邮箱" />
            </Form.Item>
            <Form.Item label="密码" >
              <Input className="fromItem" placeholder="登录密码" />
            </Form.Item>
            <div className="from-wj">
             <span onClick={()=>showDrawer('找回密码',2)}>忘记密码？</span>
            </div>
            <Form.Item  >
              <Button onClick={()=>onSuccess()} className="form-button">登录</Button>
            </Form.Item>
            <Form.Item  >
               <div className="form-zc"> 没有账号？
                 <span onClick={()=>showDrawer('注册',1)}>立即注册</span></div>
            </Form.Item>


          </Form>
        </div>
      </div>
    </div>
    <Drawer
      placement={"bottom"}
      closable={false}
      onClose={onClose}
      open={open}
      className="drawerName"
      height={'89%'}
    >
      {
        teype === 1? <Zhuce onColset={()=>onClose()}></Zhuce>:
          teype === 2? <ZhaoHui onColset={()=>onClose()}></ZhaoHui>:""
      }

    </Drawer>

  </>
}

export default  memo(Login);

